package com.jt.controller;

import com.jt.pojo.Advice;
import com.jt.pojo.User;
import com.jt.service.AdviceService;
import com.jt.vo.PageResult;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/advice")
public class AdviceController {
    @Autowired
    private AdviceService adviceService;

//    @GetMapping("/findAll")
////
////    public SysResult findAll(){
////        List<Advice> list = adviceService.findAll();
////        return SysResult.success(list);
////
////    }

    @PostMapping("/addAdvice")
    public SysResult addAdvice(@RequestBody Advice advice){
        adviceService.addAdvice(advice);
        return SysResult.success();
    }

    @DeleteMapping("/{id}")
    public SysResult deleteAdviceById(@PathVariable Integer id){
        adviceService.deleteAdviceById(id);
        return  SysResult.success();
    }

    @GetMapping("/update")
    public SysResult findAdviceById(Integer id){
        Advice advice = adviceService.findAdviceById(id);
        return  SysResult.success(advice);
    }

    @PutMapping("/updateAdvice")
    public SysResult updateAdvice(@RequestBody Advice advice){
        adviceService.updateAdvice(advice);
        return SysResult.success();
    }

    @GetMapping("/list")
    public SysResult findAdviceList(PageResult pageResult){
        pageResult = adviceService.findAdviceList(pageResult);
        return SysResult.success(pageResult);
    }





}
